const http = require('http')
const fs = require('fs')
const path = require('path')

const server = http.createServer((req, res) => {
    // 获取 请求路径
    let {pathname} = new URL(req.url, 'http://localhost:8088')
    console.log(pathname)

    let pathfile;
    if(pathname === '/'){
        pathfile = __dirname + '\\file\\index.html'
    }else if(pathname === '/index.css'){
        pathfile = __dirname + '\\file\\index.css'
    }else if(pathname === '/index.js'){
        pathfile = __dirname + '\\file\\index.js'
    }else{
        res.statusCode = 404
        res.end('404')
        return
    }
    let result = fs.readFileSync(pathfile)
    // 获取文件后缀名
    var ext = path.extname(pathfile).slice(1)
    console.log(ext)
    res.setHeader('Content-Type', 'xxx')
    res.end(result)
});

server.listen(8088, ()=>{
    console.log("listening on 8088")
});